﻿Public Class Frm_Principal

    Private Sub RegTrabajadorToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RegTrabajadorToolStripMenuItem.Click
        Dim frm As New Frm_Trabajador
        llamarform(frm, Me, 0)
    End Sub
    Public Sub llamarform(ByVal formulario As Form, ByVal mdi As Form, ByVal tipo As Integer)

        Dim frmllamado As Form
        Dim escargado As Boolean = False
        Try
            'Chequea si el formulario ha sido cargado
            For Each frmllamado In mdi.MdiChildren
                'Compara si es igual y retorna verdadero si lo es.
                If frmllamado.Text = formulario.Text Then
                    escargado = True   'Marca la bandera
                    Exit For      'Sale del loop si es verdadero
                End If
            Next
            If Not escargado Then
                'Carga el formulario si no esta llamado
                formulario.MdiParent = mdi
                formulario.Show()
            ElseIf escargado Then
                frmllamado.Focus()   'Enfoca el objeto
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
        End Try
        formulario = Nothing  'Limpiar todo
        frmllamado = Nothing
    End Sub
    'asfdasfasfd<sfd<f<f
    Private Sub Frm_Principal_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class